package b1.mobile.blackberry.io.http;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.json.me.JSONArray;
import org.xml.sax.SAXException;

import b1.mobile.blackberry.io.xml.SoapParserHandler;

import net.rim.device.api.xml.parsers.ParserConfigurationException;
import net.rim.device.api.xml.parsers.SAXParser;
import net.rim.device.api.xml.parsers.SAXParserFactory;

public class ResponseParserHelper {

	String _content;
	public ResponseParserHelper(String response){
		_content = response;
	}
	
	public Object parse(String desiredTag){
		SoapParserHandler handler = new SoapParserHandler(desiredTag);
		InputStream is = new ByteArrayInputStream(_content.getBytes());
		
		SAXParserFactory factory = SAXParserFactory.newInstance();
	    factory.setNamespaceAware(true);
	    SAXParser parser;
		
		try {
			parser = factory.newSAXParser();
			parser.parse(is, handler);
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	    return handler.getJson();
	}
}
